{{/* This partial is for pretty much all structured data (VRL stuff, CLI, API, component configs/output/telemetry, etc.) */}}
{{ $ctx := . }}
<div class="relative no-prose border dark:border-gray-700 rounded-md shadow">
  {{/* Source/transform/sink config */}}
  {{ with .component_config }}
    <div class="flex flex-col divide-y dark:divide-gray-700">
      {{ range $k, $v := . }}
        {{ if ne $k "type" }}
          {{ $name := $k }}
          <div class="p-4">
            <span class="flex justify-between items-center">
              {{/* Config name */}}
              <span class="font-mono">
                {{ partial "heading.html" (dict "text" $name "level" 3 "anchor" true "icon" false) }}
              </span>

              {{/* Config labels */}}
              <span class="flex justify-between space-x-1">
                {{ if $v.common }}
                  {{ partial "badge.html" (dict "word" "common" "color" "blue") }}
                {{ end }}

                {{ if $v.required }}
                  {{ partial "badge.html" (dict "word" "required" "color" "red") }}
                {{ else }}
                  {{ partial "badge.html" (dict "word" "optional" "color" "blue") }}
                {{ end }}

                {{ range $k, $v := $v.type }}
                  {{ $isArray := eq $k "array" }}
                  {{ if $isArray }}
                    {{ range $k, $v := $v.items.type }}
                      {{ $name := printf "[%s]" $k }}
                      {{ partial "badge.html" (dict "word" $name "color" "gray") }}
                    {{ end }}
                  {{ else }}
                    {{ partial "badge.html" (dict "word" $k "color" "gray") }}
                  {{ end }}

                  {{ with $v.syntax }}
                    {{ if eq . "remap_program" }}
                      {{ partial "badge.html" (dict "word" . "color" "gray" "href" "/docs/reference/vrl#program") }}
                    {{ else if eq . "template" }}
                      {{ partial "badge.html" (dict "word" . "color" "gray" "href" "/docs/reference/configuration/template-syntax/") }}
                    {{ else }}
                      {{ partial "badge.html" (dict "word" . "color" "gray") }}
                    {{ end }}
                  {{ end }}

                  {{ if $v.enum }}
                    {{ partial "badge.html" (dict "word" "enum" "color" "yellow") }}
                  {{ end }}
                {{ end }}
              </span>
            </span>

            {{ if $v.deprecated }}
              <div class="mt-3 border-2 rounded-md border-yellow-400 flex flex-col space-y-1.5 py-2 px-3">
                <span>
                  {{ partial "heading.html" (dict "text" "Deprecated" "level" 4 "toc_hide" true) }}
                </span>
                <div class="flex space-x-5 items-center">
                  <div class="flex-shrink-0">
                    {{/* Heroicon: outline/exclamation-circle */}}
                    <svg
                      xmlns="http://www.w3.org/2000/svg"
                      class="text-yellow-500 h-5 w-5"
                      fill="none"
                      viewBox="0 0 24 24"
                      stroke="currentColor"
                    >
                      <path
                        stroke-linecap="round"
                        stroke-linejoin="round"
                        stroke-width="2"
                        d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
                      />
                    </svg>
                  </div>

                  <div class="prose dark:prose-dark max-w-none leading-snug">
                    {{ if $v.deprecated_message }}
                      {{ $v.deprecated_message | markdownify }}
                    {{ else }}
                      This field is deprecated.
                    {{ end }}
                  </div>
                </div>
              </div>
            {{ end }}


            <div class="mt-6 prose dark:prose-dark max-w-none leading-snug text-gray-600 dark:text-gray-300">
              {{ $v.description | markdownify }}
            </div>

            {{ with $v.warnings }}
              <div class="mt-3 border-2 rounded-md border-yellow-400 flex flex-col space-y-1.5 py-2 px-3">
                <span>
                  {{ partial "heading.html" (dict "text" "Warning" "level" 4 "toc_hide" true) }}
                </span>

                {{ range . }}
                  <div class="flex space-x-5 items-center">
                    <div class="flex-shrink-0">
                      {{/* Heroicon: outline/exclamation-circle */}}
                      <svg
                        xmlns="http://www.w3.org/2000/svg"
                        class="text-yellow-500 h-5 w-5"
                        fill="none"
                        viewBox="0 0 24 24"
                        stroke="currentColor"
                      >
                        <path
                          stroke-linecap="round"
                          stroke-linejoin="round"
                          stroke-width="2"
                          d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
                        />
                      </svg>
                    </div>

                    <div class="prose dark:prose-dark max-w-none leading-snug">
                      {{ . | markdownify }}
                    </div>
                  </div>
                {{ end }}
              </div>
            {{ end }}

            {{ range $k, $v := $v.type }}
              {{ if eq $k "condition" }}
                {{ template "config-condition" (dict "name" $name "condition" $v) }}
              {{ end }}

              {{ if eq $k "object" }}
                {{/* Object (with sub-configs) */}}
                <div class="mt-4">
                  {{ template "config-object" (dict "name" $name "config" $v "level" 4) }}
                </div>
              {{ else if eq $k "array" }}
                {{/* Array */}}
                {{ with $v.items }}
                  <div class="mt-3 border rounded py-2 px-3 dark:border-gray-700">
                    {{ range $k, $v := . }}
                      {{ range $k, $v := . }}
                        <span class="flex justify-between items-center">
                          <span class="font-semibold"> Array </span>

                          <span class="flex items-center space-x-1">
                            {{ partial "badge.html" (dict "word" $k "color" "gray") }}
                            {{ if $v.syntax }}
                              {{ partial "badge.html" (dict "word" $v.syntax "color" "gray") }}
                            {{ end }}
                          </span>
                        </span>

                        {{ if eq $k "object" }}
                          <div class="mt-2">
                            {{ template "config-object" (dict "name" $name "config" $v "level" 4) }}
                          </div>
                        {{ end }}

                        {{ with $v.examples }}
                          {{ template "config-array-examples" (dict "examples" .) }}
                        {{ end }}
                      {{ end }}
                    {{ end }}
                  </div>
                {{ end }}
              {{ else }}
                {{/* Non-arrays/objects */}}
                {{ if eq $v.syntax "template" }}
                  <div class="mt-4 text-sm">
                    <strong>Note</strong>: This parameter supports Vector's
                    <a href="/docs/reference/configuration/template-syntax">template syntax</a>, which enables you to
                    use dynamic per-event values.
                  </div>
                {{ end }}

                {{ with $v.examples }}
                  {{ template "config-examples" (dict "examples" .) }}
                {{ end }}
              {{ end }}

              {{/* Enum */}}
              {{ with $v.enum }}
                <div class="mt-3 border rounded py-2 px-3 dark:border-gray-700">
                  <span class="flex justify-between items-center">
                    <span class="font-semibold"> Enum options </span>

                    <span class="flex items-center space-x-1">
                      {{ partial "badge.html" (dict "word" $k "color" "gray") }}
                      {{ partial "badge.html" (dict "word" $v.syntax "color" "gray") }}
                    </span>
                  </span>

                  <div class="mt-4 prose dark:prose-dark max-w-none">
                    {{ template "enum-options-table" . }}
                  </div>
                </div>
              {{ end }}
            {{ end }}

            {{/* Default value */}}
            {{ range $k, $v := $v.type }}
              {{ if or $v.default (eq $v.default false) }}
                <div class="mt-4">
                  {{ template "default" . }}
                </div>
              {{ end }}
            {{ end }}

            {{/* "Relevant when" conditions */}}
            {{ with .relevant_when }}
              <div class="mt-2 text-sm flex justify-end">
                <span> Relevant when: <code>{{ . }}</code> </span>
              </div>
            {{ end }}
          </div>
        {{ end }}
      {{ end }}
    </div>
  {{ end }}

  {{/* Source/transform/sink requirements */}}
  {{ with .component_requirements }}
    <div class="py-4 px-6 flex items-center">
      <div class="mr-8 flex-shrink-0">
        {{/* Heroicon: outline/exclamation */}}
        <svg
          xmlns="http://www.w3.org/2000/svg"
          class="text-yellow-500 h-6 w-6"
          fill="none"
          viewBox="0 0 24 24"
          stroke="currentColor"
        >
          <path
            stroke-linecap="round"
            stroke-linejoin="round"
            stroke-width="2"
            d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"
          />
        </svg>
      </div>
      <div class="flex flex-col space-y-4 overflow-x-auto">
        {{ range . }}
          <div class="prose dark:prose-dark max-w-none leading-normal">
            {{ . | markdownify }}
          </div>
        {{ end }}
      </div>
    </div>
  {{ end }}

  {{/* Source/transform/sink input */}}
  {{ with .component_input_types }}
    {{ template "telemetry_input" . }}
  {{ end }}

  {{/* Source/transform/sink output */}}
  {{ with .component_output_types }}
    <div class="py-3 px-5">
      {{ with .metrics }}
        <span class="flex items-center justify-between">
          {{ partial "heading.html" (dict "text" "Metrics" "level" 3 "id" "output-metrics" "href" "#output-metrics") }}


          <a href="/docs/architecture/data-model/metric">
            {{/* Heroicon: solid/question-mark-circle */}}
            <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
              <path
                fill-rule="evenodd"
                d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-8-3a1 1 0 00-.867.5 1 1 0 11-1.731-1A3 3 0 0113 8a3.001 3.001 0 01-2 2.83V11a1 1 0 11-2 0v-1a1 1 0 011-1 1 1 0 100-2zm0 8a1 1 0 100-2 1 1 0 000 2z"
                clip-rule="evenodd"
              />
            </svg>
          </a>
        </span>

        <div class="mt-3 border rounded divide-y dark:border-gray-700 dark:divide-gray-700">
          {{ template "telemetry_output" . }}
        </div>
      {{ end }}

      {{ with .traces }}
        <span class="flex items-center justify-between">
          {{ partial "heading.html" (dict "text" "Traces" "level" 3 "id" "output-traces" "href" "#output-traces") }}
        </span>

        <div class="mt-3 border rounded divide-y dark:border-gray-700 dark:divide-gray-700">
          {{ template "telemetry_output" . }}
        </div>
      {{ end }}

      {{ with .logs }}
        <span class="flex items-center justify-between">
          {{ partial "heading.html" (dict "text" "Logs" "level" 3 "id" "output-logs" "href" "#output-logs") }}


          <a href="/docs/architecture/data-model/log">
            {{/* Heroicon: solid/question-mark-circle */}}
            <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
              <path
                fill-rule="evenodd"
                d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-8-3a1 1 0 00-.867.5 1 1 0 11-1.731-1A3 3 0 0113 8a3.001 3.001 0 01-2 2.83V11a1 1 0 11-2 0v-1a1 1 0 011-1 1 1 0 100-2zm0 8a1 1 0 100-2 1 1 0 000 2z"
                clip-rule="evenodd"
              />
            </svg>
          </a>
        </span>

        <div class="mt-3 border-2 rounded-md border-yellow-400 flex flex-col space-y-1.5 py-2 px-3">
          <span>
            <h4
              x-data="{ show: false }"
              x-on:mouseover="show = true"
              x-on:mouseleave="show = false"
              id="warning"
              class="flex items-center text-dark dark:text-gray-200 js-toc-ignore"
            >
              <span>Warning</span>
              <a class="ml-2" x-show="show" href="#warning" style="display: none;"
                ><svg
                  xmlns="http://www.w3.org/2000/svg"
                  class="text-secondary dark:text-primary h-4 w-4"
                  fill="none"
                  viewBox="0 0 24 24"
                  stroke="currentColor"
                >
                  <path
                    stroke-linecap="round"
                    stroke-linejoin="round"
                    stroke-width="2"
                    d="M7 20l4-16m2 16l4-16M6 9h14M4 15h14"
                  ></path>
                </svg>
              </a>
            </h4>
          </span>
          <div class="flex space-x-5 items-center">
            <div class="flex-shrink-0">
              <svg
                xmlns="http://www.w3.org/2000/svg"
                class="text-yellow-500 h-5 w-5"
                fill="none"
                viewBox="0 0 24 24"
                stroke="currentColor"
              >
                <path
                  stroke-linecap="round"
                  stroke-linejoin="round"
                  stroke-width="2"
                  d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
                ></path>
              </svg>
            </div>
            <div class="prose dark:prose-dark max-w-none leading-snug">
              The fields shown below will be different if log namespacing is enabled. See
              <a href="/blog/log-namespacing/">Log Namespacing</a> for more details
            </div>
          </div>
        </div>

        <div class="mt-3 border rounded divide-y dark:border-gray-700 dark:divide-gray-700">
          {{ template "logs_output" . }}
        </div>
      {{ end }}
    </div>
  {{ end }}

  {{/* Source/transform outputs */}}
  {{ with .component_outputs }}
    <div class="flex flex-col divide-y dark:divide-gray-700">
      {{ range . }}
        <div class="py-3 px-5">
          <span class="flex justify-between items-center">
            <span class="font-mono">
              {{ partial "heading.html" (dict "text" .name "level" 3 "anchor" true "icon" false) }}
            </span>
          </span>

          <div class="my-3 prose dark:prose-dark max-w-none">
            {{ .description | markdownify }}
          </div>
        </div>
      {{ end }}
    </div>
  {{ end }}

  {{/* Source/transform/sink examples */}}
  {{ with .component_examples }}
    {{ $formats := slice "yaml"  "toml" "json" }}
    {{ $defaultFormat := index $formats 0 }}
    <div class="no-prose flex flex-col divide-y dark:divide-gray-700">
      {{ range . }}
        {{ $configs := .configuration }}
        {{ $id := printf "examples-%s" .title | urlize }}
        <div class="py-3 px-5 flex flex-col space-y-2">
          <span>
            {{ partial "heading.html" (dict "text" .title "level" 3 "id" $id) }}
          </span>

          <span> Given this event... </span>

          <div>
            {{ template "code" .input }}
          </div>

          <span> ...and this configuration... </span>

          <div class="py-2.5 px-3.5 border rounded dark:border-gray-700">
            <div class="flex space-x-2">
              {{ range $formats }}
                <button
                  @click="$store.global.setFormat('{{ . }}')"
                  :class="{ 'text-secondary dark:text-primary': $store.global.isFormat('{{ . }}') }"
                  class="font-semibold"
                >
                  {{ . | upper }}
                </button>
              {{ end }}
            </div>

            {{ range $formats }}
              {{ $config := index $configs . }}
              <div x-show="$store.global.isFormat('{{ . }}')" class="mt-2">
                {{ highlight $config . "" }}
              </div>
            {{ end }}
          </div>

          <span> ...this Vector event is produced: </span>

          <div>
            {{ template "code" .output }}
          </div>
        </div>
      {{ end }}
    </div>
  {{ end }}

  {{/* Source/transform/sink output */}}
  {{ with .component_telemetry }}
    <div class="py-4 px-6">
      {{ with .metrics }}
        <span class="flex items-center justify-between">
          {{ partial "heading.html" (dict "text" "Metrics" "level" 3 "id" "telemetry-metrics" "href" "#telemetry-metrics") }}


          <a href="/docs/architecture/data-model/metric"> link </a>
        </span>

        <div class="mt-3 border rounded divide-y dark:border-gray-700 dark:divide-gray-700">
          {{ template "telemetry_output" . }}
        </div>
      {{ end }}

      {{ with .logs }}
        <span class="flex items-center justify-between">
          {{ partial "heading.html" (dict "text" "Logs" "id" "telemetry-logs" "href" "#telemetry-logs") }}


          <a href="/docs/architecture/data-model/log"> link </a>
        </span>

        <div class="mt-3 border rounded divide-y dark:border-gray-700 dark:divide-gray-700">
          {{ template "telemetry_output" . }}
        </div>
      {{ end }}

    </div>
  {{ end }}

  {{/* Source/transform/sink warnings */}}
  {{ with .component_warnings }}
    <div class="no-prose py-4 px-6 flex items-center">
      <div class="mr-8 flex-shrink-0">
        <svg
          xmlns="http://www.w3.org/2000/svg"
          class="text-red-400 h-7 w-7"
          fill="none"
          viewBox="0 0 24 24"
          stroke="currentColor"
        >
          <path
            stroke-linecap="round"
            stroke-linejoin="round"
            stroke-width="2"
            d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"
          />
        </svg>
      </div>
      <div class="flex flex-col space-y-4 overflow-x-auto">
        {{ range . }}
          <div class="prose dark:prose-dark max-w-none leading-normal">
            {{ . | markdownify }}
          </div>
        {{ end }}
      </div>
    </div>
  {{ end }}

  {{/* Source/transform/sink environment variables */}}
  {{ with .component_env_vars }}
    <div class="no-prose flex flex-col divide-y dark:divide-gray-700">
      {{ range $k, $v := . }}
        <div class="py-4 px-6">
          <span class="flex justify-between items-center">
            <span class="font-mono">
              {{ $href := printf "#%s" $k | urlize }}
              {{ partial "heading.html" (dict "text" $k "level" 3 "href" $href) }}
            </span>

            <span class="flex space-x-1">
              {{ if $v.common }}
                {{ partial "badge.html" (dict "word" "common" "color" "blue") }}
              {{ end }}

              {{ if $v.required }}
                {{ partial "badge.html" (dict "word" "required" "color" "red") }}
              {{ else }}
                {{ partial "badge.html" (dict "word" "optional" "color" "blue") }}
              {{ end }}

              {{ range $k, $v := $v.type }}
                {{ partial "badge.html" (dict "word" $k "color" "gray") }}

                {{ with $v.syntax }}
                  {{ partial "badge.html" (dict "word" . "color" "gray") }}
                {{ end }}

                {{ if $v.enum }}
                  {{ partial "badge.html" (dict "word" "enum" "color" "yellow") }}
                {{ end }}
              {{ end }}
            </span>
          </span>

          <div class="mt-4 prose prose-sm dark:prose-dark max-w-none">
            {{ $v.description | markdownify }}
          </div>

          {{ range $k, $v := $v.type }}
            {{ with $v.default }}
              <span class="mt-2 text-sm"> Default: <code>{{ . }}</code> </span>
            {{ end }}
          {{ end }}

          {{ range $k, $v := $v.type }}
            {{/* Enum */}}
            {{ with $v.enum }}
              <div class="mt-3 border rounded py-2 px-3 dark:border-gray-700">
                <span class="flex justify-between items-center">
                  <span class="font-semibold"> Enum options </span>

                  <span class="flex items-center space-x-1">
                    {{ partial "badge.html" (dict "word" $k "color" "gray") }}
                    {{ partial "badge.html" (dict "word" $v.syntax "color" "gray") }}
                  </span>
                </span>

                <div class="mt-4 prose dark:prose-dark max-w-none">
                  {{ template "enum-options-table" . }}
                </div>
              </div>
            {{ end }}

            {{ with $v.examples }}
              <div x-data="{ open: false }" class="mt-3 border rounded py-2 px-3 dark:border-gray-700">
                <span class="flex justify-between items-center">
                  <span class="font-semibold"> Examples </span>

                  {{ template "config-toggler" (dict "size" 4) }}
                </span>

                <div x-show="open">
                  {{ range . }}
                    <div class="overflow-x-scroll">
                      <span class="font-mono text-sm">
                        {{ . }}
                      </span>
                    </div>
                  {{ end }}
                </div>
              </div>
            {{ end }}
          {{ end }}
        </div>
      {{ end }}
    </div>
  {{ end }}

  {{/* Data schemas (logs and metrics) */}}
  {{ with .data_schema }}
    <div class="flex flex-col divide-y dark:divide-gray-700">
      <div class="prose dark:prose-dark max-w-none py-4 px-6">
        {{ .description | markdownify }}
      </div>

      {{/* Options */}}
      <div class="py-4 px-6">
        <span>
          {{ partial "heading.html" (dict "text" "Options" "level" 3) }}
        </span>

        <div class="mt-4 border rounded flex flex-col divide-y dark:divide-gray-700 dark:border-gray-700">
          {{ range $k, $v := .type.object.options }}
            {{ $name := $k }}
            {{ $id := cond (eq $name "*") "star" $name }}
            <div class="py-4 px-6">
              <span class="flex items-center justify-between">
                <span>
                  <h3 id="{{ $id }}" class="font-semibold font-mono text-sm dark:text-primary">
                    <a href="#{{ $id }}">
                      {{ $name }}
                    </a>
                  </h3>
                </span>

                <span class="flex space-x-1">
                  {{ if $v.common }}
                    {{ partial "badge.html" (dict "word" "common" "color" "indigo") }}
                  {{ end }}

                  {{ if $v.required }}
                    {{ partial "badge.html" (dict "word" "required" "color" "red") }}
                  {{ else }}
                    {{ partial "badge.html" (dict "word" "optional" "color" "gray") }}
                  {{ end }}

                  {{ range $k, $v := $v.type }}
                    {{ $type := cond (eq $k "object") "table" $k }}
                    {{ partial "badge.html" (dict "word" $type "color" "green") }}
                  {{ end }}
                </span>
              </span>

              {{ with $v.description }}
                <div class="mt-3">
                  {{ . | markdownify }}
                </div>
              {{ end }}


              <div>
                {{ range $k, $v := $v.type }}
                  {{ if eq $k "object" }}
                    <div class="mt-3">
                      <div class="border rounded flex flex-col divide-y dark:border-gray-700 dark:divide-gray-700">
                        {{ range $k, $v := $v.options }}
                          {{ $id := printf "%s-%s" $name $k }}
                          <div class="py-3 px-5">
                            <span class="flex justify-between items-center">
                              <span class="font-mono font-semibold">
                                <h4 id="{{ $id }}">
                                  <a href="#{{ $id }}">
                                    {{ $k }}
                                  </a>
                                </h4>
                              </span>

                              <span class="flex space-x-1">
                                {{ if $v.required }}
                                  {{ partial "badge.html" (dict "word" "required" "color" "red") }}
                                {{ else }}
                                  {{ partial "badge.html" (dict "word" "optional" "color" "gray") }}
                                {{ end }}

                                {{ range $k, $v := $v.type }}
                                  {{ partial "badge.html" (dict "word" $k "color" "green") }}

                                  {{ with $v.syntax }}
                                    {{ partial "badge.html" (dict "word" . "color" "gray") }}
                                  {{ end }}

                                  {{ if $v.enum }}
                                    {{ partial "badge.html" (dict "word" "enum" "color" "yellow") }}
                                  {{ end }}
                                {{ end }}
                              </span>
                            </span>

                            <div class="prose dark:prose-dark max-w-none">
                              {{ $v.description | markdownify }}
                            </div>

                            {{ range $k, $v := $v.type }}
                              {{ with $v.examples }}
                                <div class="mt-2">
                                  <span class="font-semibold"> Examples </span>

                                  <span class="flex space-x-2">
                                    {{ range . }}
                                      <span class="font-mono text-sm text-secondary dark:text-primary">
                                        {{ . }}
                                      </span>
                                    {{ end }}
                                  </span>
                                </div>
                              {{ end }}
                            {{ end }}
                          </div>
                        {{ end }}
                      </div>
                    </div>
                  {{ end }}
                {{ end }}
              </div>
            </div>
          {{ end }}
        </div>
      </div>

      {{/* Examples */}}
      {{ with .type.object.examples }}
        <div class="py-4 px-6">
          <span>
            {{ partial "heading.html" (dict "text" "Examples" "level" 3) }}
          </span>

          <div class="mt-4 flex flex-col divide-y dark:divide-gray-700 dark:border-gray-700">
            {{ range . }}
              {{ template "code" . }}
            {{ end }}
          </div>
        </div>
      {{ end }}
    </div>
  {{ end }}

  {{/* VRL function info (/vrl/functions) */}}
  {{ with .vrl_functions }}
    <div class="flex flex-col divide-y dark:divide-gray-700">
      {{ range . }}
        {{ $name := .name }}
        {{ $func := index site.Data.docs.remap.functions .name }}
        {{ $infallible := not $func.internal_failure_reasons }}
        {{ $args := $func.arguments }}
        {{ $requiredArgs := where $args "required" true }}
        {{ $optionalArgs := where $args "required" false }}
        {{ $lastArg := sub (len $args) 1 }}
        {{ $return := $func.return }}
        <div class="py-4 px-6">
          {{/* Function title */}}
          <span class="flex justify-between items-center">
            <span class="font-mono">
              {{ $href := printf "#%s" $name }}
              {{ partial "heading.html" (dict "text" $name "level" 3 "href" $href "icon" false) }}
            </span>

            {{/* Badges */}}
            <span class="flex space-x-1">
              {{ $href := "/docs/reference/vrl/expressions/#function-call-characteristics" | relURL }}
              {{ if $infallible }}
                {{ partial "badge.html" (dict "word" "infallible" "color" "blue" "inline" true "href" $href) }}
              {{ else }}
                {{ partial "badge.html" (dict "word" "fallible" "color" "yellow" "inline" true "href" $href) }}
              {{ end }}
              {{/* Deprecation Badge */}}
              {{ if $func.deprecated }}
                {{ partial "badge.html" (dict "word" "deprecated" "color" "red" "inline" true "href" $href) }}
              {{ end }}
              {{/* Pure Badge */}}
              {{ if $func.pure }}
                {{ partial "badge.html" (dict "word" "pure" "color" "green" "inline" true "href" $href) }}
              {{ else }}
                {{ partial "badge.html" (dict "word" "impure" "color" "yellow" "inline" true "href" $href) }}
              {{ end }}
            </span>
          </span>

          {{/* Function description */}}
          <div class="mt-6 prose prose-md dark:prose-dark max-w-none">
            {{ $func.description | markdownify }}
          </div>

          {{/* Function spec, etc. */}}
          {{ $id := printf "%s-function-spec" $name }}
          <div class="mt-6">
            <span>
              {{ partial "heading.html" (dict "text" "Function spec" "level" 4 "id" $id "toc_hide" true) }}
            </span>

            <div class="my-2 font-mono text-sm bg-dark dark:bg-black px-3.5 py-2.5 rounded text-gray-100">
              <span class="text-primary-dark dark:text-primary font-semibold">{{ $name }}</span>(
              {{- $lastArg := sub (len $requiredArgs) 1 -}}
              {{- range $idx, $arg := $requiredArgs -}}
                {{ $isLast := eq $idx $lastArg -}}
                <span class="font-bold text-secondary dark:text-primary"> {{- .name -}} </span>:
                <span class="text-gray-200">
                  &lt;{{ delimit .type `<span class="text-grey-500"> | </span>` | safeHTML }}&gt; </span
                >{{ if not $isLast }},{{ end -}}
              {{ end -}}
              {{- if gt (len $optionalArgs) 0 -}}
                ,
                [{{- $lastArg := sub (len $optionalArgs) 1 -}}
                {{- range $idx, $arg := $optionalArgs -}}
                  {{ $isLast := eq $idx $lastArg -}}
                  <span class="text-indigo-500 dark:text-indigo-300"> {{- .name -}} </span>:
                  <span class="text-gray-200">
                    &lt;{{ delimit .type `<span class="text-grey-500"> | </span>`  | safeHTML }}&gt; </span
                  >{{ if not $isLast }},{{ end -}}
                {{ end -}}]
              {{ end }})
              {{- with $return -}}
                <div class="ml-3">
                  <span class="font-extrabold">::</span>
                  <span class="text-gray-200"> &lt;{{ delimit .types " | " }}&gt; </span>{{ if not $infallible }}
                    , &lt;error&gt;
                  {{ end }}
                </div>
              {{- end -}}
            </div>

            <div class="mt-3 flex flex-row-reverse">
              {{ template "vrl-function-legend" }}
            </div>

            {{/* Function arguments */}}
            {{ with $args }}
              <div class="mt-6 prose dark:prose-dark max-w-none">
                {{ template "vrl-function-args" . }}
              </div>
            {{ end }}

            {{/* Function notices */}}
            {{ with $func.notices }}
              {{ $id := printf "%s-notices" $name }}
              <div class="mt-6">
                <span>
                  {{ partial "heading.html" (dict "text" "Notices" "level" 4 "id" $id "toc_hide" true) }}
                </span>

                <span class="mt-2 text-sm prose prose-md dark:prose-dark max-w-none">
                  This function has special behavior that you should be aware of.
                </span>

                <div class="mt-1.5 flex flex-col space-y-2">
                  {{ range . }}
                    <div class="flex space-x-5 items-center">
                      <div class="flex-shrink-0 py-1">
                        {{/* Heroicon: outline/exclamation-circle */}}
                        <svg
                          xmlns="http://www.w3.org/2000/svg"
                          class="text-yellow-500 h-5 w-5"
                          fill="none"
                          viewBox="0 0 24 24"
                          stroke="currentColor"
                        >
                          <path
                            stroke-linecap="round"
                            stroke-linejoin="round"
                            stroke-width="2"
                            d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
                          />
                        </svg>
                      </div>

                      <div class="prose prose-sm dark:prose-dark max-w-none leading-snug">
                        {{ . | markdownify }}
                      </div>
                    </div>
                  {{ end }}
                </div>
              </div>
            {{ end }}

            {{/* Function errors */}}
            {{ with $func.internal_failure_reasons }}
              {{ $id := printf "%s-errors" $name }}
              <div class="mt-6">
                <span>
                  {{ partial "heading.html" (dict "text" "Errors" "level" 4 "id" $id "toc_hide" true) }}
                </span>

                <span class="mt-2 text-sm prose prose-md dark:prose-dark max-w-none">
                  The <code>{{ $name }}</code> function is <strong>fallible</strong>, which means that
                  <a href="/docs/reference/vrl/errors">error handling</a> is required for these errors:
                </span>

                <div class="mt-1.5">
                  {{ range . }}
                    <div class="flex space-x-5 items-center">
                      <div class="flex-shrink-0 py-1">
                        {{/* Heroicon: outline/exclamation */}}
                        <svg
                          xmlns="http://www.w3.org/2000/svg"
                          class="text-red-400 h-5 w-5"
                          fill="none"
                          viewBox="0 0 24 24"
                          stroke="currentColor"
                        >
                          <path
                            stroke-linecap="round"
                            stroke-linejoin="round"
                            stroke-width="2"
                            d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"
                          />
                        </svg>
                      </div>

                      <div class="prose prose-sm dark:prose-dark max-w-none leading-snug">
                        {{ . | markdownify }}
                      </div>
                    </div>
                  {{ end }}
                </div>
              </div>
            {{ end }}

            {{/* Function examples */}}
            {{ with $func.examples }}
              {{ $id := printf "%s-examples" $name }}
              <div class="mt-6">
                <span>
                  {{ partial "heading.html" (dict "text" "Examples" "level" 4 "id" $id "toc_hide" true) }}
                </span>

                <div class="mt-2 flex flex-col space-y-4">
                  {{ range . }}
                    {{ template "vrl-function-example" (dict "name" $name "ctx" .) }}
                  {{ end }}
                </div>
              </div>
            {{ end }}
          </div>
        </div>
      {{ end }}
    </div>
  {{ end }}

  {{/* Real-world examples */}}
  {{ with .vrl_real_world_examples }}
    <div class="flex flex-col divide-y dark:divide-gray-700">
      {{ range . }}
        {{ $input := dict "message" .input.log.message | jsonify (dict "indent" "  ") }}
        {{ $vrlSourceCode := highlight .source "toml" "" }}
        {{ $output := .output | jsonify (dict "indent" "  ") }}
        {{ $outputCode := highlight $output "json" "" }}
        <div class="py-3 px-5">
          <span class="font-semibold tracking-tight">
            {{ $href := printf "#%s" (.title | urlize) }}
            {{ partial "heading.html" (dict "text" .title "level" 3 "href" $href "icon" false) }}
          </span>

          <div class="mt-3 flex flex-col space-y-2">
            {{ with .input.log }}
              {{ $json := . | jsonify (dict "indent" "  ") }}
              {{ $code := highlight $json "json" "" }}
              <span>
                Given this
                <a href="/docs/architecture/data-model/log">Vector log event</a>...
              </span>
              {{ $code }}
            {{ end }}

            {{ with .input.metric }}
              {{ $json := . | jsonify (dict "indent" "  ") }}
              {{ $code := highlight $json "json" "" }}
              <span>
                Given this
                <a href="/docs/architecture/data-model/metric">Vector metric event</a>...
              </span>
              {{ $code }}
            {{ end }}


            <span> ...and this VRL program... </span>

            {{ $vrlSourceCode }}

            {{ if .raises }}
              {{ $errorCode := highlight .raises.compiletime "rust" "" }}
              <span> ...you should see this error: </span>

              {{ $errorCode }}
            {{ else }}
              {{ with .input.log }}
                <span>...the following log event is output:</span>
              {{ end }}

              {{ with .input.metric }}
                <span>...the following metric event is output:</span>
              {{ end }}

              {{ $outputCode }}
            {{ end }}
          </div>
        </div>
      {{ end }}
    </div>
  {{ end }}

  {{/* Compile-time errors */}}
  {{ with .vrl_compile_time_errors }}
    <div class="divide-y dark:divide-gray-700">
      {{ range $code, $error := . }}
        {{ $id := printf "%s %s" $code $error.title | urlize }}
        <div class="p-6">
          <span>
            <h3 id="{{ $code }}">
              <span class="font-mono text-secondary">
                {{ $code }}
              </span>

              <a href="#{{ $code }}" class="text-gray-700 dark:text-white tracking-tight">
                {{ $error.title }}
              </a>
            </h3>
          </span>

          <div x-show="open" class="mt-4">
            {{ with $error.description }}
              <div class="leading-tight">
                {{ . | markdownify }}
              </div>
            {{ end }}

            {{ with $error.rationale }}
              {{ $id := printf "error-%s-rationale" $code }}
              <div class="mt-3">
                <span class="flex items-center space-x-1.5">
                  {{/* Heroicon: outline/zoom-in */}}
                  <svg
                    xmlns="http://www.w3.org/2000/svg"
                    class="h-4 w-4 text-indigo-500 dark:text-indigo-400"
                    fill="none"
                    viewBox="0 0 24 24"
                    stroke="currentColor"
                  >
                    <path
                      stroke-linecap="round"
                      stroke-linejoin="round"
                      stroke-width="2"
                      d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0zM10 7v3m0 0v3m0-3h3m-3 0H7"
                    />
                  </svg>

                  {{ partial "heading.html" (dict "text" "Rationale" "level" 4 "id" $id "toc_hide" true) }}
                </span>

                <div class="mt-2 leading-tight">
                  {{ . | markdownify }}
                </div>
              </div>
            {{ end }}

            {{ with $error.resolution }}
              {{ $id := printf "error-%s-resolution" $code }}
              <div class="mt-3">
                <span class="flex items-center space-x-1.5">
                  {{/* Heroicon: outline/trending-up */}}
                  <svg
                    xmlns="http://www.w3.org/2000/svg"
                    class="h-4 w-4 text-blue-500 dark:text-blue-400"
                    fill="none"
                    viewBox="0 0 24 24"
                    stroke="currentColor"
                  >
                    <path
                      stroke-linecap="round"
                      stroke-linejoin="round"
                      stroke-width="2"
                      d="M5 3v4M3 5h4M6 17v4m-2-2h4m5-16l2.286 6.857L21 12l-5.714 2.143L13 21l-2.286-6.857L5 12l5.714-2.143L13 3z"
                    />
                  </svg>

                  {{ partial "heading.html" (dict "text" "Resolution" "level" 4 "id" $id "toc_hide" true) }}
                </span>

                <div class="mt-2 leading-tight">
                  {{ . | markdownify }}
                </div>
              </div>
            {{ end }}

            {{ with $error.examples }}
              {{ $id := printf "error-%s-examples" $code }}
              <div
                x-data="{ open: location.hash.startsWith('#error-{{ $code }}') }"
                class="mt-5 rounded-md px-3 py-2 dark:border-gray-700 border"
              >
                <span class="flex justify-between items-center">
                  <span class="flex items-center space-x-2">
                    {{/* Heroicon: outline/code */}}
                    <svg
                      xmlns="http://www.w3.org/2000/svg"
                      class="h-4 w-4 text-secondary dark:text-primary"
                      fill="none"
                      viewBox="0 0 24 24"
                      stroke="currentColor"
                    >
                      <path
                        stroke-linecap="round"
                        stroke-linejoin="round"
                        stroke-width="2"
                        d="M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4"
                      />
                    </svg>

                    {{ partial "heading.html" (dict "text" "Examples" "level" 4 "toc_hide" true "id" $id) }}
                  </span>

                  {{ template "vrl-toggler" }}
                </span>

                <div
                  x-show="open"
                  class="mt-2 flex flex-col divide-y dark:divide-gray-700 border rounded dark:border-gray-700"
                >
                  {{ range . }}
                    {{ $id := printf "error-%s-example-%s" $code (.title | urlize) }}
                    <div class="flex flex-col space-y-1 py-2.5 px-4 rounded-sm dark:border-gray-700">
                      <span>
                        {{ partial "heading.html" (dict "text" .title "level" 5 "id" $id "toc_hide" true) }}
                      </span>

                      {{/* Example event (log or metric) */}}
                      {{ with .input }}
                        {{ with .log }}
                          {{/* Log event */}}
                          {{ $json := . | jsonify (dict "indent" "  ") }}
                          <div>
                            <span class="tracking-tighter font-semibold text-sm"> Log event </span>

                            {{ highlight $json "json" "" }}
                          </div>
                        {{ end }}

                        {{ with .metric }}
                          {{/* Metric event */}}
                          {{ $json := . | jsonify (dict "indent" "  ") }}
                          <div>
                            <span class="tracking-tighter font-semibold text-sm"> Metric event </span>

                            {{ highlight $json "json" "" }}
                          </div>
                        {{ end }}
                      {{ end }}

                      {{ with .source }}
                        <div>
                          <span class="tracking-tighter font-semibold text-sm"> VRL program </span>

                          {{ highlight . "coffee" "" }}
                        </div>
                      {{ end }}

                      {{/* Example diff */}}
                      {{ with .diff }}
                        <div>
                          <span class="tracking-tighter font-semibold text-sm"> How to fix it </span>

                          {{ highlight . "diff" "" }}
                        </div>
                      {{ end }}
                    </div>
                  {{ end }}
                </div>
              </div>
            {{ end }}
          </div>
        </div>
      {{ end }}
    </div>
  {{ end }}

  {{/* VRL expressions */}}
  {{ with .vrl_expressions }}
    <div class="divide-y dark:divide-gray-700">
      {{ range $k, $v := . }}
        <div class="py-4 px-6">
          <span>
            {{ partial "heading.html" (dict "text" $v.title "level" 3) }}
          </span>

          <div class="mt-6 prose dark:prose-dark max-w-none leading-snug">
            {{ $v.description | markdownify }}
          </div>

          {{ with $v.grammar }}
            {{ $id := printf "%s-grammar" $k }}
            <div class="mt-4">
              <span>
                {{ partial "heading.html" (dict "text" "Grammar" "level" 4 "id" $id) }}
              </span>
            </div>

            <div class="mt-2 border rounded p-4 dark:border-gray-700">
              <div>
                {{ highlight .source "coffee" "" }}
              </div>

              {{ with .definitions }}
                <div class="mt-3 prose dark:prose-dark max-w-none">
                  <table>
                    <thead>
                      <tr>
                        <th>Argument</th>
                        <th>Meaning</th>
                      </tr>
                    </thead>
                    <tbody>
                      {{ range $k, $v := . }}
                        <tr>
                          <td>
                            <code>
                              {{ $k }}
                            </code>
                          </td>
                          <td>
                            {{ $v.description | markdownify }}
                          </td>
                        </tr>
                      {{ end }}
                    </tbody>
                  </table>
                </div>
              {{ end }}
            </div>
          {{ end }}

          {{ with $v.examples }}
            {{ $id := printf "%s-examples" $k }}
            <div class="mt-6">
              <span>
                {{ partial "heading.html" (dict "text" "Examples" "level" 4 "id" $id) }}
              </span>

              <div
                class="mt-3 no-prose border rounded-md flex flex-col divide-y dark:border-gray-700 dark:divide-gray-700"
              >
                {{ range . }}
                  {{ template "vrl-data-example" (dict "name" $k "ctx" .) }}
                {{ end }}
              </div>
            </div>
          {{ end }}

          {{ with $v.characteristics }}
            {{ $id := printf "%s-characteristics" ($v.title | urlize) }}
            <div class="mt-4">
              <span>
                {{ partial "heading.html" (dict "text" "Characteristics" "level" 4 "id" $id) }}
              </span>

              <div class="mt-2 flex flex-col divide-y dark:divide-gray-700 border dark:border-gray-700">
                {{ range . }}
                  <div class="py-1.5 px-3">
                    {{ partial "heading.html" (dict "text" .title "level" 5 "icon" false) }}

                    {{ with .description }}
                      <div class="mt-1 prose prose-sm dark:prose-dark max-w-none">
                        {{ . | markdownify }}
                      </div>
                    {{ end }}

                    {{ with .enum }}
                      <div class="mt-2">
                        <span> Enum options </span>

                        <div class="prose dark:prose-dark max-w-none">
                          {{ template "enum-options-table" . }}
                        </div>
                      </div>
                    {{ end }}
                  </div>
                {{ end }}
              </div>
            </div>
          {{ end }}
        </div>
      {{ end }}
    </div>
  {{ end }}

  {{/* VRL examples */}}
  {{ with .vrl_examples }}
    <div class="flex flex-col divide-y dark:divide-gray-700">
      {{ range . }}
        {{ $name := .name }}
        {{ $link := printf "docs/reference/vrl/functions/#%s" $name | relURL }}
        <div class="py-4 px-6">
          <span class="text-base font-mono">
            {{ partial "heading.html" (dict "text" $name "level" 3) }}
          </span>

          <div class="my-4 prose dark:prose-dark max-w-none leading-snug">
            {{ .description | markdownify }}
          </div>

          <div class="border rounded divide-y dark:border-gray-700 dark:divide-gray-700">
            {{ range .examples }}
              <div class="py-3 px-5">
                <span class="font-semibold">
                  {{ partial "heading.html" (dict "text" .title "level" 4) }}
                </span>

                <div class="mt-2">
                  <span> Source </span>

                  <div class="mt-1">
                    {{ highlight .source "coffee" "" }}
                  </div>
                </div>

                {{ with .return }}
                  <div class="mt-2.5">
                    <span> Return </span>

                    <div class="mt-1">
                      {{ template "code" . }}
                    </div>
                  </div>
                {{ end }}


                <div class="mt-4 flex items-center space-x-2 justify-end">
                  <span>
                    {{/* Heroicon: outline/light-bulb */}}
                    <svg
                      xmlns="http://www.w3.org/2000/svg"
                      class="text-yellow-500 h-4 w-4"
                      fill="none"
                      viewBox="0 0 24 24"
                      stroke="currentColor"
                    >
                      <path
                        stroke-linecap="round"
                        stroke-linejoin="round"
                        stroke-width="2"
                        d="M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z"
                      />
                    </svg>
                  </span>

                  <span class="text-sm">
                    Learn more about the
                    <a
                      href="{{ $link }}"
                      class="font-mono font-semibold text-secondary dark:text-primary hover:text-primary dark:hover:text-secondary"
                      >{{ $name }}</a
                    >
                    function
                  </span>
                </div>
              </div>
            {{ end }}
          </div>
        </div>
      {{ end }}
    </div>
  {{ end }}

  {{/* VRL syntax */}}
  {{ with .vrl_syntax }}
    <div class="flex flex-col divide-y dark:divide-gray-700">
      {{ range . }}
        {{ $title := .title }}
        <div class="py-4 px-6">
          {{ partial "heading.html" (dict "text" .title "level" 3) }}

          {{ with .description }}
            <div class="mt-2 prose dark:prose-dark max-w-none">
              {{ . | markdownify }}
            </div>
          {{ end }}

          {{ with .examples }}
            {{ $id := printf "%s-examples" (urlize $title) }}
            <div class="mt-3">
              <span>
                {{ partial "heading.html" (dict "text" "Examples" "level" 4 "id" $id) }}
              </span>

              <div class="mt-2 flex flex-col space-y-2">
                {{ range . }}
                  {{ highlight . "text" "" }}
                {{ end }}
              </div>
            </div>
          {{ end }}
        </div>
      {{ end }}
    </div>
  {{ end }}

  {{/* VRL literals */}}
  {{ with .vrl_literals }}
    <div class="flex flex-col divide-y dark:divide-gray-700">
      {{ range $k, $v := . }}
        <div class="py-4 px-6">
          <span>
            {{ partial "heading.html" (dict "text" $v.title "level" 3 "icon" false) }}
          </span>

          {{ with $v.description }}
            <div class="mt-2 prose dark:prose-dark max-w-none leading-6">
              {{ . | markdownify }}
            </div>
          {{ end }}

          {{ with $v.examples }}
            {{ $id := printf "%s-examples" ($v.title | urlize) }}
            <div class="mt-4">
              <span>
                {{ partial "heading.html" (dict "text" "Examples" "level" 4 "id" $id) }}
              </span>

              <div class="mt-2 flex flex-col space-y-2 text-sm">
                {{ range . }}
                  {{ highlight . "coffee" "" }}
                {{ end }}
              </div>
            </div>
          {{ end }}

          {{ with $v.characteristics }}
            {{ $id := printf "%s-characteristics" ($v.title | urlize) }}
            <div class="mt-4">
              <span>
                {{ partial "heading.html" (dict "text" "Characteristics" "level" 4 "id" $id) }}
              </span>

              <div class="mt-2 flex flex-col divide-y dark:divide-gray-700 border dark:border-gray-700">
                {{ range . }}
                  <div class="py-1.5 px-3">
                    {{ partial "heading.html" (dict "text" .title "level" 5 "icon" false) }}

                    {{ with .description }}
                      <div class="mt-1 prose prose-sm dark:prose-dark max-w-none">
                        {{ . | markdownify }}
                      </div>
                    {{ end }}

                    {{ with .enum }}
                      <div class="mt-2">
                        <span> Enum options </span>

                        <div class="prose dark:prose-dark max-w-none">
                          {{ template "enum-options-table" . }}
                        </div>
                      </div>
                    {{ end }}
                  </div>
                {{ end }}
              </div>
            </div>
          {{ end }}
        </div>
      {{ end }}
    </div>
  {{ end }}

  {{/* VRL concepts */}}
  {{ with .vrl_concepts }}
    <div class="flex flex-col divide-y dark:divide-gray-700">
      {{ range $k, $v := . }}
        {{ $id := .anchor }}
        <div class="py-3 px-5">
          <span>
            {{ partial "heading.html" (dict "text" $v.title "level" 3) }}
          </span>

          <div class="mt-2 prose dark:prose-dark max-w-none">
            {{ $v.description | markdownify }}
          </div>

          {{ with $v.characteristics }}
            {{ $id := printf "%s-characteristics" $id }}
            <div class="mt-3">
              <span>
                {{ partial "heading.html" (dict "text" "Characteristics" "level" 4 "id" $id) }}
              </span>

              <div class="mt-2 flex flex-col divide-y border rounded-sm dark:border-gray-700 dark:divide-gray-700">
                {{ range . }}
                  <div class="py-2 px-4">
                    <span class="font-semibold">
                      {{ partial "heading.html" (dict "text" .title "level" 5) }}
                    </span>

                    <div class="mt-2 prose prose-sm dark:prose-dark max-w-none">
                      {{ .description | markdownify }}
                    </div>
                  </div>
                {{ end }}
              </div>
            </div>
          {{ end }}
        </div>
      {{ end }}
    </div>
  {{ end }}

  {{/* VRL features */}}
  {{ with .vrl_features }}
    <div class="flex flex-col divide-y dark:divide-gray-700">
      {{ range . }}
        {{ $id := .anchor }}
        <div class="py-3 px-5">
          <span>
            {{ partial "heading.html" (dict "text" .title "level" 3) }}
          </span>

          <div class="mt-3 prose dark:prose-dark max-w-none">
            {{ .description | markdownify }}
          </div>

          {{ with .characteristics }}
            {{ $id := printf "%s-characteristics" $id }}
            <div class="mt-3">
              <span>
                {{ partial "heading.html" (dict "text" "Characteristics" "level" 4) }}
              </span>

              <div class="mt-2 flex flex-col space-y-2">
                {{ range . }}
                  <div>
                    {{ partial "heading.html" (dict "text" .title "level" 5) }}


                    <div class="mt-2 prose prose-sm dark:prose-dark max-w-none">
                      {{ .description | markdownify }}
                    </div>
                  </div>
                {{ end }}
              </div>
            </div>
          {{ end }}
        </div>
      {{ end }}
    </div>
  {{ end }}

  {{/* VRL principles */}}
  {{ with .vrl_principles }}
    <div class="flex flex-col divide-y dark:divide-gray-700">
      {{ range . }}
        <div class="py-4 px-6">
          <span>
            {{ partial "heading.html" (dict "text" .title "level" 3) }}
          </span>

          <div class="mt-3 prose dark:prose-dark max-w-none">
            {{ .description | markdownify }}
          </div>
        </div>
      {{ end }}
    </div>
  {{ end }}

  {{/* Vector process */}}
  {{ with .process }}
    <div class="flex flex-col divide-y dark:divide-gray-700">
      {{/* Signals */}}
      <div class="py-3 px-5">
        <span>
          {{ partial "heading.html" (dict "text" "Signals" "level" 3 "anchor" true) }}
        </span>

        <div class="my-4 prose dark:prose-dark max-w-none leading-snug">
          {{ .process_signals.description | markdownify }}
        </div>

        <div class="mt-2 prose dark:prose-dark max-w-none">
          <table>
            <thead>
              <tr>
                <th>Signal</th>
                <th>Description</th>
              </tr>
            </thead>
            <tbody>
              {{ range .process_signals.signals }}
                <tr>
                  <td>
                    <code>{{ .name }}</code>
                  </td>
                  <td>
                    {{ .description | markdownify }}
                  </td>
                </tr>
              {{ end }}
            </tbody>
          </table>
        </div>
      </div>

      {{/* Exit codes */}}
      <div class="py-3 px-5">
        <span>
          {{ partial "heading.html" (dict "text" "Exit codes" "level" 3 "anchor" true) }}
        </span>

        <div class="my-4 prose dark:prose-dark max-w-none leading-snug">
          {{ .exit_codes.description | markdownify }}
        </div>

        <div class="prose dark:prose-dark max-w-none">
          <table>
            <thead>
              <tr>
                <th>Code</th>
                <th>Description</th>
              </tr>
            </thead>
            <tbody>
              {{ range .exit_codes.codes }}
                <tr>
                  <td>
                    <code>{{ .code }}</code>
                  </td>
                  <td>
                    {{ .description | markdownify }}
                  </td>
                </tr>
              {{ end }}
            </tbody>
          </table>
        </div>
      </div>
    </div>
  {{ end }}

  {{ with .component_permissions }}
    <div class="flex flex-col divide-y dark:divide-gray-700">
      {{ range . }}
        {{/* TODO: remove the need for this double loop in the CUE sources */}}
        {{ range . }}
          <div class="py-3 px-5">
            <span class="text-lg">
              Platform:
              <a href="{{ .platform_link }}">
                <strong>
                  {{ .platform_title }}
                </strong>
              </a>
            </span>

            <div class="mt-2">
              <span class="text-md"> Relevant policies </span>

              <div class="p-3 prose dark:prose-dark max-w-none">
                <table>
                  <thead>
                    <tr>
                      <th>Policy</th>
                      <th>Required for</th>
                      <th>Required when</th>
                    </tr>
                  </thead>
                  <tbody>
                    {{ range .policies }}
                      <tr>
                        <td>
                          <a href="{{ .docs_url }}">
                            <code>
                              {{ .action }}
                            </code>
                          </a>
                        </td>
                        <td>
                          <ul>
                            {{ range .required_for }}<li><code>{{ . }}</code></li>{{ end }}
                          </ul>
                        </td>
                        <td>
                          {{ .required_when | markdownify }}
                        </td>
                      </tr>
                    {{ end }}
                  </tbody>
                </table>
              </div>
            </div>
          </div>
        {{ end }}
      {{ end }}
    </div>
  {{ end }}
</div>

{{ define "enum-options-table" }}
  <table class="table-auto">
    <thead>
      <tr>
        <th>Option</th>
        <th>Description</th>
      </tr>
    </thead>
    <tbody>
      {{ range $k, $v := . }}
        <tr>
          <td>
            <code>{{ $k }}</code>
          </td>
          <td>
            {{ $v | markdownify }}
          </td>
        </tr>
      {{ end }}
    </tbody>
  </table>
{{ end }}

{{ define "config-examples" }}
  <div x-data="{ open: false }" class="mt-2.5 border rounded py-2 px-3 dark:border-gray-700">
    <span class="flex justify-between items-center">
      <span class="text-sm"> Examples </span>

      {{ template "config-toggler" (dict "size" 4) }}
    </span>

    <div x-show="open" class="mt-3 text-sm flex flex-col space-y-2">
      {{ range .examples }}
        {{ $json := . | jsonify (dict "indent" "  ") }}
        {{ highlight $json "json" "" }}
      {{ end }}
    </div>
  </div>
{{ end }}

{{ define "config-array-examples" }}
  {{ $json := .examples | jsonify (dict "indent" "  ") }}
  <div x-data="{ open: false }" class="mt-2 border rounded py-2 px-3 dark:border-gray-700">
    <span class="flex justify-between items-center">
      <span class="text-sm"> Examples </span>

      {{ template "config-toggler" (dict "size" 4) }}
    </span>

    <div x-show="open" class="mt-3 text-sm flex flex-col space-y-2">
      {{ highlight $json "json" "" }}
    </div>
  </div>
{{ end }}

{{ define "config-toggler" }}
  {{ $size := .size | default 4 }}
  <a @click="open = !open" class="cursor-pointer">
    {{/* Heroicon: outline/chevron-down */}}
    <svg
      x-show="!open"
      xmlns="http://www.w3.org/2000/svg"
      class="h-{{ $size }} w-{{ $size }}"
      fill="none"
      viewBox="0 0 24 24"
      stroke="currentColor"
    >
      <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7" />
    </svg>

    {{/* Heroicon: outline/chevron-up */}}
    <svg
      x-show="open"
      xmlns="http://www.w3.org/2000/svg"
      class="h-{{ $size }} w-{{ $size }}"
      fill="none"
      viewBox="0 0 24 24"
      stroke="currentColor"
    >
      <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 15l7-7 7 7" />
    </svg>
  </a>
{{ end }}

{{ define "default" }}
  <div class="flex flex-row-reverse">
    <span class="text-sm">
      <span class="font-semibold">default:</span>
      <code>{{ .default }}</code>{{ with .unit }}({{ . }}){{ end }}
    </span>
  </div>
{{ end }}

{{ define "vrl-function-example" }}
  {{ $id := printf "%s-examples-%s" .name (.ctx.title | urlize) }}
  <div>
    <span>
      {{ partial "heading.html" (dict "text" .ctx.title "level" 5 "id" $id "toc_hide" true) }}
    </span>

    <div class="flex flex-col space-y-2">
      <div>
        <span class="font-light"> Source </span>

        <div class="text-sm">
          {{ template "code" .ctx.source }}
        </div>
      </div>

      {{ with .ctx.return }}
        <div>
          <span class="font-light"> Return </span>

          <div class="text-sm">
            {{ template "code" . }}
          </div>
        </div>
      {{ end }}
    </div>
  </div>
{{ end }}

{{ define "vrl-function-legend" }}
  {{/* Heroicon: outline/map */}}
  <div class="flex items-center space-x-2">
    <svg
      xmlns="http://www.w3.org/2000/svg"
      class="text-gray-400 dark:text-gray-300 h-4 w-4"
      fill="none"
      viewBox="0 0 24 24"
      stroke="currentColor"
    >
      <path
        stroke-linecap="round"
        stroke-linejoin="round"
        stroke-width="2"
        d="M9 20l-5.447-2.724A1 1 0 013 16.382V5.618a1 1 0 011.447-.894L9 7m0 13l6-3m-6 3V7m6 10l4.553 2.276A1 1 0 0021 18.382V7.618a1 1 0 00-.553-.894L15 4m0 13V4m0 0L9 7"
      />
    </svg>

    <span class="font-mono text-xs text-secondary dark:text-primary font-semibold"> required </span>

    <span class="font-mono text-xs text-indigo-500 dark:text-indigo-300 font-semibold"> optional </span>

    <span class="font-mono text-xs text-gray-500 dark:text-gray-300 font-semibold"> &lt;types | ...&gt; </span>
  </div>
{{ end }}

{{ define "vrl-function-arg-row" }}
  {{ $color := cond .required "text-secondary dark:text-primary" "text-indigo-500 dark:text-indigo-300" }}
  <tr>
    <td>
      <span class="font-mono {{ $color }}{{ if .required }}font-bold{{ end }}">
        {{ .name }}
      </span>
    </td>
    <td>
      <span class="font-mono">
        {{ range .type }}
          {{ . }}<br />
        {{ end }}
      </span>
    </td>
    <td class="leading-snug">
      {{ .description | markdownify }}
    </td>
    <td class="overflow-auto">
      {{ with .default }}
        <code>{{ . }}</code>
      {{ end }}
    </td>
    <td>
      {{ if .required }}
        <span>yes</span>
      {{ else }}
        <span>no</span>
      {{ end }}
    </td>
  </tr>
{{ end }}

{{ define "vrl-function-args" }}
  {{ $required := where . "required" true }}
  {{ $optional := where . "required" false }}
  <table class="table-fixed">
    <thead>
      <tr>
        <th class="w-1/6">Argument</th>
        <th class="w-1/6">Type</th>
        <th class="w-1/2">Description</th>
        <th class="w-1/6">Default</th>
        <th>Required?</th>
      </tr>
    </thead>
    <tbody>
      {{ range $required }}
        {{ template "vrl-function-arg-row" . }}
      {{ end }}

      {{ range $optional }}
        {{ template "vrl-function-arg-row" . }}
      {{ end }}
    </tbody>
  </table>
{{ end }}

{{ define "vrl-toggler" }}
  <button @click="open = !open">
    {{/* Heroicon: outline/chevron-down */}}
    <svg
      x-show="!open"
      xmlns="http://www.w3.org/2000/svg"
      class="h-4 w-4 text-gray-600 dark:text-gray-400 hover:text-secondary dark:hover:text-primary"
      fill="none"
      viewBox="0 0 24 24"
      stroke="currentColor"
    >
      <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7" />
    </svg>

    {{/* Heroicon: outline/chevron-up */}}
    <svg
      x-show="open"
      xmlns="http://www.w3.org/2000/svg"
      class="h-4 w-4 text-gray-600 dark:text-gray-400 hover:text-secondary dark:hover:text-primary"
      fill="none"
      viewBox="0 0 24 24"
      stroke="currentColor"
    >
      <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 15l7-7 7 7" />
    </svg>
  </button>
{{ end }}

{{ define "vrl-data-example" }}
  {{ $id := printf "%s-example-%s" .name (urlize .ctx.title) }}
  <div class="py-3 px-5">
    {{ with .ctx.title }}
      {{ partial "heading.html" (dict "text" . "level" 5 "id" $id "bold" true) }}
    {{ end }}


    <div class="mt-3 flex flex-col space-y-2.5">
      {{ with .ctx.input }}
        <div>
          <span class="font-semibold text-gray-600 dark:text-gray-300"> Vector event </span>

          <div class="mt-2">
            {{ template "code" . }}
          </div>
        </div>
      {{ end }}

      {{ with .ctx.source }}
        <div>
          <span class="font-semibold text-gray-600 dark:text-gray-300"> VRL program </span>

          <div class="mt-2">
            {{ template "code" . }}
          </div>
        </div>
      {{ end }}

      {{ with .ctx.return }}
        <div>
          <span class="font-semibold text-gray-600 dark:text-gray-300"> Resulting event </span>

          <div class="mt-2">
            {{ template "code" . }}
          </div>
        </div>
      {{ end }}
    </div>
  </div>
{{ end }}

{{ define "config-object" }}
  {{ $prefix := .name }}
  {{ $level := .level }}
  {{ $innerLevel := add $level 1 }}
  <div class="border dark:border-gray-700 rounded flex flex-col divide-y dark:divide-gray-700">
    {{ range $k, $v := .config.options }}
      {{ $name := printf "%s.%s" $prefix $k }}
      <div class="py-3 px-4">
        <div class="flex justify-between items-center">
          <span>
            {{ partial "heading.html" (dict "text" $name "level" $level "anchor" true "icon" false "mono" true) }}
          </span>

          <span class="flex space-x-1">
            {{ if $v.common }}
              {{ partial "badge.html" (dict "word" "common" "color" "blue") }}
            {{ end }}

            {{ if $v.required }}
              {{ partial "badge.html" (dict "word" "required" "color" "red") }}
            {{ else }}
              {{ partial "badge.html" (dict "word" "optional" "color" "blue") }}
            {{ end }}

            {{ range $k, $v := $v.type }}
              {{ $isArray := eq $k "array" }}
              {{ if $isArray }}
                {{ range $k, $v := $v.items.type }}
                  {{ $name := printf "[%s]" $k }}
                  {{ partial "badge.html" (dict "word" $name "color" "gray") }}
                {{ end }}
              {{ else }}
                {{ partial "badge.html" (dict "word" $k "color" "gray") }}
              {{ end }}

              {{ with $v.syntax }}
                {{ if eq . "remap_program" }}
                  {{ partial "badge.html" (dict "word" . "color" "gray" "href" "/docs/reference/vrl#program") }}
                {{ else if eq . "template" }}
                  {{ partial "badge.html" (dict "word" . "color" "gray" "href" "/docs/reference/configuration/template-syntax/") }}
                {{ else }}
                  {{ partial "badge.html" (dict "word" . "color" "gray") }}
                {{ end }}
              {{ end }}

              {{ if $v.enum }}
                {{ partial "badge.html" (dict "word" "enum" "color" "yellow") }}
              {{ end }}
            {{ end }}
          </span>
        </div>

        <div class="mt-4 prose dark:prose-dark max-w-none leading-snug">
          {{ $v.description | markdownify }}
        </div>

        {{ if eq $v.type.string.syntax "template" }}
          <div class="mt-4 text-sm">
            <strong>Note</strong>: This parameter supports Vector's
            <a href="/docs/reference/configuration/template-syntax">template syntax</a>, which enables you to use
            dynamic per-event values.
          </div>
        {{ end }}

        {{ with $v.relevant_when }}
          <div class="mt-2">
            <span> Relevant when: <code>{{ . }}</code> </span>
          </div>
        {{ end }}

        {{ range $k, $v := $v.type }}
          {{ if eq $k "object" }}
            <div class="mt-4">
              {{ template "config-object" (dict "name" $name "config" $v "level" $innerLevel) }}
            </div>
          {{ end }}

          {{ if eq $k "condition" }}
            {{ template "config-condition" (dict "name" "*" "condition" $v) }}
          {{ end }}

          {{ with $v.enum }}
            <div class="mt-4">
              <span class="font-semibold"> Enum options </span>

              <div class="mt-2 prose dark:prose-dark max-w-none">
                {{ template "enum-options-table" . }}
              </div>
            </div>
          {{ end }}

          {{ with $v.examples }}
            {{ template "config-examples" (dict "examples" .) }}
          {{ end }}

          {{ if or $v.default (eq $v.default false) }}
            <div class="mt-4">
              {{ template "default" . }}
            </div>
          {{ end }}
        {{ end }}
      </div>
    {{ end }}
  </div>
{{ end }}

{{ define "code" }}
  {{ if reflect.IsMap . }}
    {{/* If a map or array, highlight as JSON */}}
    {{ $json := . | jsonify (dict "indent" "  ") }}
    {{ highlight $json "json" "" }}
  {{ else if reflect.IsSlice . }}
    {{ $json := . | jsonify }}
    {{ highlight $json "json" "" }}
  {{ else if hasPrefix . "```" }}
    {{/* If a code sample, translate into Markdown */}}
    {{ . | markdownify }}
  {{ else }}
    {{/* If just a plain old string, use Ruby syntax highlighting as a best guess */}}
    {{ highlight . "ruby" "" }}
  {{ end }}
{{ end }}

{{ define "config-condition" }}
  {{ $configName := .name }}
  <div class="mt-4">
    <div class="border rounded dark:border-gray-700 divide-y dark:divide-gray-700">
      {{ range $k, $v := .condition.options }}
        {{ $id := printf "%s.%s" $configName $k }}
        <div class="py-3 px-5">
          <div>
            {{ partial "heading.html" (dict "text" $id "level" 4 "mono" true) }}
          </div>

          <div class="mt-2 prose dark:prose-dark max-w-none">
            {{ $v.description | markdownify }}
          </div>
        </div>
      {{ end }}
    </div>

    <div class="my-4 ml-2">
      <span>
        {{ partial "heading.html" (dict "text" "Available syntaxes" "level" 3 "icon" false "toc_hide" true) }}
      </span>

      <table class="table-auto">
        <thead>
          <tr>
            <th>Syntax</th>
            <th>Description</th>
            <th>Example</th>
          </tr>
        </thead>
        <tbody>
          {{ range .condition.syntaxes }}
            <tr>
              <td>
                <code>
                  {{ .name }}
                </code>
              </td>
              <td>
                {{ .description | markdownify }}
              </td>
              <td>
                <code>{{ .example }}</code>
              </td>
            </tr>
          {{ end }}
        </tbody>
      </table>

      <div class="py-3 px-5 border rounded-md border-green-500">
        <span>
          {{ partial "heading.html" (dict "text" .condition.shorthand_explainer.title "level" 3 "icon" false "toc_hide" true) }}
        </span>

        <div class="mt-2 prose dark:prose-dark max-w-none">
          {{ .condition.shorthand_explainer.description | markdownify }}
        </div>
      </div>

      <div class="mt-4">
        <span>
          {{ partial "heading.html" (dict "text" "Condition config examples" "level" 3) }}
        </span>

        <div class="mt-2 flex flex-col space-y-2">
          {{ range .condition.condition_examples }}
            {{ $name := .name }}
            {{ $example := .example }}
            {{ $vrlOnly := .vrl_only }}
            <div class="flex flex-col space-y-2">
              <span>
                {{ partial "heading.html" (dict "text" .title "level" 4) }}
              </span>

              {{ $formats := slice "yaml"  "toml" "json" }}
              <div class="flex space-x-2">
                {{ range $formats }}
                  <button
                    @click="$store.global.setFormat('{{ . }}')"
                    :class="{ 'text-secondary dark:text-primary': $store.global.isFormat('{{ . }}') }"
                    class="font-semibold"
                  >
                    {{ . | upper }}
                  </button>
                {{ end }}
              </div>

              {{ range $formats }}
                {{ $code := "" }}
                {{ $shorthand := "" }}
                {{ if eq . "toml" }}
                  {{ $code = printf "%s = { type = \"%s\", source = \"%s\" }" $configName $name $example }}
                  {{ $shorthand = printf "%s = \"%s\"" $configName $example }}
                {{ else if eq . "yaml" }}
                  {{ $code = printf "%s:\n  type: \"%s\"\n  source: \"%s\"" $configName $name $example }}
                  {{ $shorthand = printf "%s: \"%s\"" $configName $example }}
                {{ else if eq . "json" }}
                  {{ $code = printf "\"%s\": {\n  \"type\": \"%s\",\n  \"source\": \"%s\"\n}" $configName $name $example }}
                  {{ $shorthand = printf "\"%s\": \"%s\"" $configName $example }}
                {{ end }}
                <div x-show="$store.global.isFormat('{{ . }}')" class="mt-2">
                  {{ if $vrlOnly }}
                    {{ highlight $shorthand . "" }}
                  {{ else }}
                    {{ highlight $code . "" }}
                  {{ end }}
                </div>
              {{ end }}
            </div>
          {{ end }}
        </div>
      </div>
    </div>
  </div>
{{ end }}
